#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 叶建伟
   @Email: yejw46507@hundsun.com
   @Time: 2022/6/30 16:52
   @File: 产品风险评估审核.py
"""
import time

from 基础公共脚本.common import Table
from 基础公共脚本.步骤检查_hui2 import check_table, check_table_rows,FE
from 基础公共脚本.common_util import auto_fill_form,click_submit,check_label_radio,click_save,textarea_input
from 基础公共脚本.公共方法_hui2 import open_menu

def product_level_confirm(input_data=None, ui_expect=None):
    open_menu({'子系统名称': '反洗钱系统', '菜单名称': '首页'})

    # 资源设置搜索框表单填入
    time.sleep(2)
    FE.button(idname={'xpath':'//div[@class="h-layout-menu-item-wrap"]/div/span[text()="首页"]'}).click()
    time.sleep(2)
    FE.button(idname={'xpath': '//tbody[@class="h-table-tbody"]/tr[1]/td[1]/div[@class="h-table-cell h-table-cell-ellipsis"]'}).click()
    time.sleep(2)
    FE.table().select_row({'产品名称':input_data.get('产品名称')})
    time.sleep(2)
    fill_core(input_data.get("基本情况"))
    if input_data.get("评注意见"):
        FE.input_type(idname={'xpath':'//textarea[@placeholder="请输入评注意见"]'}).set_value(input_data.get("评注意见"))
    if input_data.get("文件信息"):
        FE.button(idname={'xpath':'//button/span[text()="上传文件"]'}).click()
        Table().enclosure_import(input_data.get("文件信息"))
    if input_data.get("风险等级"):
        check_label_radio(input_data.get("风险等级"))
    time.sleep(2)
    FE.button(idname={'xpath':'//div[@class="h-drawer-content"]/descendant::button/span[text()="保存"]'}).click()
    time.sleep(2)
    if input_data.get("附件上传"):
        FE.button(idname={'xpath':'//div/p[text()="附件上传"]'}).click()
        Table().enclosure_import(input_data.get("附件上传"))
    if input_data.get("审批意见"):
        textarea_input("审批意见",input_data.get("审批意见"))
    # 产品资金募集渠道
    click_submit()
    FE.button(input_data.get("审核状态")).click()
    # 检查查询结果
    # check_table_rows(input_data=None, ui_expect=ui_expect)

def fill_core(inputdata):

    for input_key, input_value in inputdata.items():
        if input_value == '' or input_value == ' ':
            continue
        else:
            input_value_list = input_value.split('/')
            if len(input_value_list) > 1:
                FE.button(idname={'xpath':'//td[contains(text(),"'+str(input_key)+'")]/parent::tr/td/div[contains(@class,"h-select h-select-single")]'}).click()
                FE.button(idname={'xpath':'//td[contains(text(),"'+str(input_key)+'")]/parent::tr/td/descendant::li[contains(text(),"'+input_value_list[0]+'")]'}).click()
                FE.input_type(idname={'xpath':'//td[contains(text(),"'+str(input_key)+'")]/parent::tr/td/descendant::textarea'}).set_value(input_value_list[1])
            else:
                FE.button(idname={
                    'xpath': '//td[contains(text(),"' + str(input_key) + '")]/parent::tr/td/div[contains(@class,"h-select h-select-single")]'}).click()
                FE.button(idname={
                    'xpath': '//td[contains(text(),"' + str(input_key) + '")]/parent::tr/td/descendant::li[contains(text(),"' +
                             input_value_list[0] + '")]'}).click()

